class Solution {

public:

	int countPairs(vector<int>& nums, int target) {

		sort(nums.begin(), nums.end());

		int count = 0;

		for (int j = nums.size() - 1; j > 0; --j)//i<j

			for (int i = 0; i < j; ++i)

			{

				if (nums[i] + nums[j] < target)

					count++;

				else

					break;

			}

		return count;

	}

};
